﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Think.Lenovo.Com.Models.NewsModel;
using Think.Lenovo.Com.DataAccess.NewsInfo;
using Think.Lenovo.Com.Models;
using Think.Lenovo.Com.DataAccess;

namespace Think.Lenovo.Com
{
    public partial class ViewsNewsPage : System.Web.UI.Page
    {
        NewsInfo info = new NewsInfo();
        NewsModel model = new NewsModel();
        News_user nuser = new News_user();
        News_userInfo nuinfo = new News_userInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Bind_Data();
                if(nuinfo.GetCount(1,Int32.Parse(Request.QueryString["id"]))<0)
                {
                    LinkButton1.Enabled = false;
                }
            }
        }

        public void Bind_Data()
        {
            int id = Int32.Parse(Request.QueryString["id"]);
            model = info.GetNewsInfo(id);

            l_title.Text = model.Title;
            l_time.Text = model.ReleaseDate.Value.Year + "年" + model.ReleaseDate.Value.Month + "月" + model.ReleaseDate.Value.Day + "日 " + model.ReleaseDate.Value.Date.ToShortDateString();
            l_source.Text = model.Source;
            l_Content.Text = model.Content;
            l_target.Text = model.Target;
            if (model.Sign == 1)
            {
                LinkButton1.Visible = true;
            }
            else
            {
                LinkButton1.Visible = false;
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            if (nuinfo.Add(nuser) > 0)
            {
                LinkButton1.Enabled = false;
            }
        }
    }
}